package TUILayer;//makes this class a part of the TUILayer package
import java.util.Scanner;
import ControlLayer.*;//The TUILayer needs to know the ControlLayer
/**
 * 
 * @Author (Alexander Hvidberg, Dennis Kirkebak & Thomas Kulmbach)
 * @Team (Group 1)
 * @Version (08/11/13)
 * 
 */
public class MainMenuUI
{
  //the reference to the ControlLayer
   private AddressBookUI adrUI;
   private DvdUI DvdUI;
   private RentalUI rentalUI;
   //references to other UI objects
   /**
    * The constuctor for the class MainMenuUI
    */
   public MainMenuUI()
   {
      
      
   }
   
   /**
    * Takes the user input and starts the next menu accordingly
    */
   public void mainMenuStart()
   {
        boolean exit=false;
        while (!exit) //! means while exit not is true (that is: false)
        {
            int choise = writeMainMenu();
            if(choise == 1)
            {
                startAddressBook();
            }
            else{
                    if(choise == 2){ 
                        startDvd();
                    }
                    else{
                        if(choise == 3){
                            startRental();
                            }//end if
                        else{
                            writeEnd();
                            exit = true;
                        }//end else
                    }// end else
             }//end else
        }//end while
    }//end start
   
    /**
     * This method writes the main menu and returns the users input
     * 
     * @return int choise - returns the input 
     */
   private int writeMainMenu()
    {       
            // creates a keyboard object to read input
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** MainMenu ***");
            System.out.println(" (1) AddressBook");
            System.out.println(" (2) DVDs");
            System.out.println(" (3) Rental");
            System.out.println(" (4) Close");
            System.out.print("\n Make your choise: ");
            
            int choise = keyboard.nextInt();
            
            return choise;
    }
    
    /**
     * Starts the addressbook menu
     */
    private void startAddressBook()
    {
        adrUI= new AddressBookUI();
        adrUI.start();
        //the adrUI needs to have a reference to the address controller
        //main controller can return references to the other controllers
     
    }

    /**
     * Starts the dvd menu
     */
    private void startDvd()
    {
        DvdUI= new DvdUI();
        DvdUI.start();
        //the DvdUI needs to have a reference to the DVD controller
        //main controller can return references to the other controllers
     
    }
    
    /**
     * Starts the rental menu
     */
    private void startRental()
    {
        rentalUI = new RentalUI();
        rentalUI.start();
    }
    
    /**
     * Write a shutdown message
     */
    private void writeEnd()
    {
        System.out.println(" The System is shutting down ");
    }
 }
